/**
*	企业加入
**/
app.controller('gJoinCtrl', ['$scope', '$state', '$stateParams', '$http', '$window', 'gConfig', 'utils',
  function($scope, $state, $stateParams, $http, $window, gConfig, utils) {

    // 列表等信息
    $scope.pageData = {
      industryList: [], // 行业
      productsMainList: [], // 主营商品
      pruductsList: []  // 详细商品
    };

    // 表单数据
    $scope.formData = {
      industry: null,
      productsMain: null,
      pruducts: null,
    }

    // 获取行业信息
    $scope.getOptioinData = function (id, grade, dataItem, callback) {
      utils.get('GetBusessByID', {
          id: id,
          grade: grade
      }).success(function (rs) {
        $scope.pageData[dataItem] = rs;
        if (typeof callback === 'function') {callback();}
      });
    }

    // 获取初始行业信息
    $scope.getOptioinData(-1, -1, 'industryList', function () {

      var id = $scope.pageData.industryList[0].companyBusinessID;
      $scope.formData.industry = $scope.pageData.industryList[0];
      // 获取主营商品
      $scope.getOptioinData(id, 1, 'productsMainList', function () {
        var _pId = $scope.pageData.productsMainList[0].companyBusinessID;
        $scope.formData.productsMain = $scope.pageData.productsMainList[0];
        $scope.getOptioinData(_pId, 2, 'pruductsList', null);
      })
    });

    // 改变行业
    $scope.changeIndustry = function () {
      // 获取主营商品
      $scope.getOptioinData($scope.formData.industry.companyBusinessID, 1, 'productsMainList', function () {
        var _pId = $scope.pageData.productsMainList[0].companyBusinessID;
        $scope.formData.productsMain = $scope.pageData.productsMainList[0];
        $scope.getOptioinData(_pId, 2, 'pruductsList', null);
      })
    };

    // 改变主营商品
    $scope.changeProductsMain = function () {
      $scope.getOptioinData($scope.formData.productsMain.companyBusinessID, 2, 'pruductsList', null);
    };

    // 后退
    $scope.goBack = function () {
      $window.history.back();
    }
  }
]);
